﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.IO;
using System.Globalization;

namespace CaptchaDemoWebsite
{
    public partial class _Default : System.Web.UI.Page
    {
        protected override void InitializeCulture()
        {
            base.InitializeCulture();
            if (Request.Form["cmbLanguages"] != null)
            {
                System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(Request.Form["cmbLanguages"]);
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(Request.Form["cmbLanguages"]);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            vcaptcha.HeaderText = "<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button><h4>" + GetErrTitle() + "</h4>";
            if (Request.QueryString["lng"] != null)
            {
                if (!IsPostBack)
                {
                    captchacontrol1.CaptchaLanguage = Request.QueryString["lng"].ToString();
                    cmbLanguages.SelectedValue = Request.QueryString["lng"].ToString();
                }                
            }
        }

        protected void cmbLanguages_SelectedIndexChanged(object sender, EventArgs e)
        {
            Response.Redirect("Default.aspx?lng=" + cmbLanguages.SelectedValue);
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {
                Response.Redirect("Success.aspx");
            }
        }

        public string GetErrTitle()
        {
            string localresourcestring = "";
            try
            {
                localresourcestring = (String)GetLocalResourceObject("errtitle");
            }
            catch
            {
                localresourcestring = "Error";
            }
            return localresourcestring;
        }
    }
}
